'use strict';

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
  if (s.length === 1) return 1;
  const n = s.length;
  const subStr = [];
  let max = 0;

  for (let i = 0; i < n - 1; i++) {
    subStr.push(s[i]);
    for (let j = i + 1; j < n; j++) {
      if (!subStr.includes(s[j])) {
        subStr.push(s[j]);
      } else {
        max = subStr.length > max ? subStr.length : max;
        subStr.length = 0;
        break;
      }
    }
    max = subStr.length > max ? subStr.length : max;
    subStr.length = 0;
  }

  return max;
};

const s = 'pwwkew';
console.log(lengthOfLongestSubstring(s));
